package pl.kosmowska.ewelina.client.app.activity.places;

import pl.kosmowska.ewelina.client.app.requestfactory.dto.OutcomeDataProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;

public class OutcomeEditPlace extends Place {
	 private static boolean isOutcome;
	  
	  @Prefix("DodajZmienWydatek")
	  public static class Tokenizer implements PlaceTokenizer<OutcomeEditPlace> {

	    private RequestFactory requestFactory;
	    
	    public Tokenizer(RequestFactory requestFactory) {
	      this.requestFactory = requestFactory;
	    }
	    	    
	    @Override
	    public String getToken(OutcomeEditPlace place) {
	      String s = "";
	      if (place.getOutcomeDataId() != null) {
	        s = requestFactory.getHistoryToken(place.getOutcomeDataId());
	      } else if (place.getOutcomeData() != null) {
	        s = requestFactory.getHistoryToken(place.getOutcomeData().stableId());
	      }else{
	        s = "new"; 
	      }

	      return s;
	    }

	    /**
	     * from - url activated
	     */
	    @Override
	    public OutcomeEditPlace getPlace(String token) {
	      EntityProxyId<OutcomeDataProxy> outcomeDataId = null;
	      if (token == null || token.trim().length() == 0 || token.equals("new") == true) {
	        // new
	      } else {
	        outcomeDataId = requestFactory.<OutcomeDataProxy> getProxyId(token);
	      }
	      return new OutcomeEditPlace(outcomeDataId);
	    }

	  }
	     
	  /**
	   * from app place move
	   */
	  private OutcomeDataProxy outcomeData;
	  
	  /**
	   * from url place move
	   */
	  private EntityProxyId<OutcomeDataProxy> outcomeDataId;
	  
	  
	  public boolean isOutcome() {
		return isOutcome;
	}

	  
	  public OutcomeEditPlace(OutcomeDataProxy outcomeData) {
	    this.outcomeData = outcomeData;
	  }

	  public OutcomeEditPlace(EntityProxyId<OutcomeDataProxy> outcomeDataId) {
	    this.outcomeDataId = outcomeDataId;
	  }
	  

	  public OutcomeEditPlace(boolean isOutcome) {
		    this.isOutcome=isOutcome;
	}


	public EntityProxyId<OutcomeDataProxy> getOutcomeDataId() {
		    return outcomeDataId;
		  }
	  
	  public OutcomeDataProxy getOutcomeData() {
		    return outcomeData;
		  }
	 
	}


